param (
    [string]$User="",
    [string]$User_pwd="",
    [string]$DatabaseName=""
)

$DATA_BACKUP_AGENT_HOME = (Get-ChildItem env:DATA_BACKUP_AGENT_HOME).Value
$Location = $DATA_BACKUP_AGENT_HOME + "\DataBackup\ProtectClient\Plugins\GeneralDBPlugin\bin\applications\exchange\ps1_scripts"
Set-Location -Path $Location
[string]$common_file_path = (Get-Location).Path + "\Common.ps1"
[string]$pssession_name = "GetDatabaseStatus"
[string]$ExchangeHost = hostname

# 引用Common.ps1
. $common_file_path

# 建立连接
if (!(NewConnection $User $User_Pwd $pssession_name)) {
    return
}

try {
    $db_name = $DatabaseName + "\" + $ExchangeHost
    $db_status = Invoke-Command -Session $Session -ScriptBlock {Get-MailboxDatabaseCopyStatus -Identity $using:db_name}
} catch {
    ClosePSSession $pssession_name
    return
}
$db_status.Status
ClosePSSession $pssession_name
